Skip to content

[NFC] Fix undefined behavior with misaligned write#920

Open
namikukr-qc wants to merge 2 commits intoqualcomm:mainfrom
namikukr-qc:misaligned_ubsan
Open

[NFC] Fix undefined behavior with misaligned write#920
namikukr-qc wants to merge 2 commits intoqualcomm:mainfrom
namikukr-qc:misaligned_ubsan

Conversation

@namikukr-qc
Copy link

@namikukr-qc namikukr-qc commented Mar 6, 2026

in emitGroup, there's an integer-sized write that triggers a sanitizer error (writing to an int-sized slot that isn't 4-byte aligned). This patch removes that and uses memcpy instead, to avoid the strict aliasing violation.

The pointer is shifted by Index * sizeof(llvm::ELF::Elf32_Word), which should make sure nothing changes functionally.

Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

in emitGroup, there's an integer-sized write that triggers
a sanitizer error (writing to an int-sized slot that isn't
4-byte aligned). This patch hacks around the warning by copying to
a uint8_t *, not considered misaligned.

The pointer is shifted by Index * sizeof(uint32_t), which should
make sure nothing changes functionally.

Signed-off-by: Namish Kukreja <namikukr@qti.qualcomm.com>
Signed-off-by: Namish Kukreja <namikukr@qti.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants